package model;

import java.awt.Color;
import java.awt.Graphics;

public class Paddle {
	
	private int x;
	private int y;

	public static final int SIZE_X = 8;
	public static final int SIZE_Y = 50;
	public static final int MARGIN = 10;

	private static final Color COLOR = Color.WHITE;
	private static int SPEED = 5;

	private int dy;

	public Paddle() {
		this.x = Game.WIDTH - 20;
		this.y = Game.HEIGHT / 2;
		dy = 0;
	}

	public void moveUp() {
		dy = -1;
	}

	public void moveDown() {
		dy = 1;
	}

	public void move() {
		y += SPEED * dy;
		handleBoundary();
	}
	
	public void stop() {
		dy = 0;
	}

	public void draw(Graphics g) {
		Color savedCol = g.getColor();
		g.setColor(COLOR);
		g.fillRect(getX() - SIZE_X / 2, getY() - SIZE_Y / 2, SIZE_X, SIZE_Y);
		g.setColor(savedCol);
	}

	protected void handleBoundary() {
		if (y + SIZE_Y / 2 > Game.HEIGHT - MARGIN) {
			stop();
			y = Game.HEIGHT - SIZE_Y / 2 - MARGIN;
		}
		else if (y - SIZE_Y / 2 < MARGIN) {
			stop();
			y = SIZE_Y / 2 + MARGIN;
		}
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

}
